Mon Nov 09 12:42:50 2015

Organisation

  • Send me your presentation until Tuesday November 17, 2015
  • If you have interactive graphs please be shure to have them also in an offline version
  • If you use data please provide the source (OpenStreetMap, Google, Eurostat etc.)
  • Please give some background information about the data source
  • If you use R to produce maps, please send me your code (Example: myCode.R)

Presentation techniques

  • You can use LaTeX Beamer/Powerpoint/Rstudio or whatever you want
  • If you use Powerpoint please produce also a pdf version
  • You can also use Rstudio to produce presentations (makes sense for interactive maps)

Presentations with Rstudio I

Presentations with Rstudio II

Presentations with Rstudio III

Questions

  • How to get popups in interactive plots?
  • How to plot two maps side by side?
  • How to deal with extreme values in color coding of spplot?
  • How to save plots?

Example on Campsites

Overview of Campsite data

kable(CampSites[1:8,1:4])
X name tourism website
1 Campingplatz Winkelbachtal camp_site http://www.gruibingen.de/campingplatz.html
2 Radler-Zeltplatz camp_site NA
3 Campingplatz des Naturfreundehauses camp_site NA
4 Campingplatz Am Aichstruter Stausee camp_site NA
5 NA camp_site NA
6 Kandern camp_site NA
7 Campingplatz Baiersbronn-Obertal camp_site NA
8 Campingplatz Schwabenmühle camp_site NA

Get a map for Germany

library(raster)
DEU1 <- getData('GADM', country='DEU', level=1)
plot(DEU1)

Add Campsites

plot(DEU1)
points(y=CampSites$lat,x=CampSites$lon,col="red",pch=20)

Change the alpha level

plot(DEU1)
points(y=CampSites$lat,x=CampSites$lon,col=rgb(0,1,0,.2),
       pch=20)

Get a google map for Germany

library(ggmap)
DE_Map <- qmap("Germany", zoom=6, maptype="hybrid")
DE_Map

Plot points on google map

DE_Map + geom_point(aes(x = lon, y = lat),
                    data = CampSites)

Density plot

DE_Map + geom_density2d(data = CampSites,                  aes(x = lon, y = lat),lwd=1.5)

Another density plot

DE_Map + stat_density2d(data = CampSites, 
aes(x = lon, y = lat,fill = ..level..), bins = 100, 
geom = 'polygon')

Another density plot

DE_Map + stat_density2d(data=CampSites, 
                        aes(x=lon,y=lat,fill=..level..,
alpha = ..level..),bins=80,geom='polygon')

Make the interactive map

Prepare an interactive map

library(magrittr)
library(leaflet)
m <- leaflet() %>%
  addTiles() %>%  
  addMarkers(lng=CampSites$lon, 
             lat=CampSites$lat, 
             popup=CampSites$name)
m

Push more information

popupInfo <- paste(CampSites$name,"\n",CampSites$website)
m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=CampSites$lon, 
             lat=CampSites$lat, 
             popup=popupInfo)
m

Result is here:

http://rpubs.com/Japhilko82/CampSitesHL

The resulting map

Popups in interactive map

How to publish on Rpubs

ggmap: two plots side by side

url <- "https://raw.githubusercontent.com/Japhilko/
GeoData/master/2015/data/whcSites.csv"
UNESCO <- read.csv(url)
name_en latitude longitude
Cultural Landscape and Archaeological Remains of the Bamiyan Valley 34.84694 67.82525
Minaret and Archaeological Remains of Jam 34.39656 64.51606
Historic Centres of Berat and Gjirokastra 40.06944 20.13333
Butrint 39.75111 20.02611

Get sites for Germany

library(ggmap)
ind <- UNESCO$states_name_en=="Germany"
UNESCO_DE <- UNESCO[ind,]

Plot first map

library(ggplot2)
DE_Map + geom_point(aes(x = longitude, y = latitude),
                    data = UNESCO_DE)

Produce two maps

library(ggplot2)
DNunesco <- UNESCO_DE[UNESCO_DE$category=="Natural",]
DCunesco <- UNESCO_DE[UNESCO_DE$category=="Cultural",]

Csites <- DE_Map + geom_point(aes(x = longitude, 
                                  y = latitude),
                              data =DCunesco,
                              col="orange", size= 3)

Nsites <- DE_Map + geom_point(aes(x = longitude, 
                                  y = latitude),
                              data = DNunesco,
                              col="green", size= 3)

Two plots side by side

library(gridExtra)
grid.arrange(Csites, Nsites, ncol=2)

Load the data

url <- "https://raw.githubusercontent.com/Japhilko/
GeoData/master/2015/data/Unemployment07a13.csv"

Unemp <- read.csv(url) 

Overview data

GEO Val2007M12 Val2013M01
EU28 6.9 10.9
EU27 6.9 10.9
EU25 6.9 11.0
EU15 6.9 11.1
EA 7.3 12.0
EA19 7.3 12.0
EA18 7.4 12.0
EA17 7.4 12.0

Usage of package tmap

library(tmap)
data(Europe)

Match the data

iso_a2<- substr(Europe@data$iso_a3,1,2)
ind <- match(iso_a2,Unemp$GEO)
Europe@data$Val2007M12 <- Unemp$Val2007M12[ind]
Europe@data$Val2013M01 <- Unemp$Val2013M01[ind]

Make the map

qtm(Europe,c("Val2007M12","Val2013M01"))

A pie chart

Students <- c(100, 200,30)
pie(Students)

Save graphics

pdf("pie_Students.pdf")
pie(Students)
dev.off()
## png 
##   2